let { HttpRequest, globalData, mfutil, UserAccess, addUserStat, URLChangeCommon } = getApp();
const app = getApp();


Page({
  data: {
    tilesDetail: {  // 详情数据

    },
    router: '/pages/no_prize/no_prize',
  },
  onLoad(options) {
    my.hideShareMenu({
      success() {
      },
      fail() {
      },
    });
    console.log(options, "opentions---------------------------------------------");
    let { id, lucky_image, lucky_text, prize_name, prize_sku, cta } = options;
    this.setData({
      id, lucky_image, lucky_text, prize_name, prize_sku, cta: JSON.parse((cta))
    })
    console.log(this.setData.lucky_text,"1122");
    this.setData({
      loadingActive: false
    })
    console.log(options, "qqqqqqqqqqqqqqqqqqqqqsss");
    this.initPage()
    /**
* 用户行为记录埋点
*/
    let routerArr = getCurrentPages();
    let params = app.globalData.params;
    let channel = app.globalData.channel;
    let UserAccessoptions = {
      grade: routerArr.length > 1 ? routerArr[routerArr.length - 2].data.router : '',
      name: routerArr[routerArr.length - 1].data.pagetitle,
      address: options.id,
    }
    let track = UserAccess(UserAccessoptions)
    // 自定义埋点
    let customAccessoptions = {
      customType: 'TileCover_' + options.id,
      // tileId: options.id
    }
    console.log(options.id, '进入奖品结束页');
    let tracks = addUserStat(customAccessoptions)
  },

  // 初始化数据
  async initPage() {
    try {
      let { id } = this.data;
      let path = `/vans-family/api/v2.1/project/vansFamily/cms/forward/get?url=/v2/cms/api/tile/${id}`;
      let parmasObj = {
        member_id_type: 1,
        member_id: globalData.userInfo.memberId
      }
      this.setData({
        loadingActive: false
      })
      let res = await HttpRequest(path, 'POST', parmasObj, {});
      this.data.tilesDetail = res.data.data
      console.log(res, "22222222222222222222222333333333444444444");
    } catch (err) {
      console.log(err, "111111111");
    }

    if (res.data.code == 0) {
      tilesDetail = res.data.data;
      let { type } = tilesDetail.tile_info;
      this.setData({
        tilesDetail,
      })
      this.setData({
        loadingActive: false
      })
    }
    this.setData({
      loadingActive: false
    })
    console.log(this.data.tilesDetail);


  },
  // 优惠卷 链接跳转
  urlChange(event) {


    let { item } = event.currentTarget.dataset;
    console.log(item);

    URLChangeCommon(item)

    /**
* 用户行为记录埋点
*/
    let routerArr = getCurrentPages();
    let params = app.globalData.params;
    let channel = app.globalData.channel;
    let UserAccessoptions = {
      grade: routerArr.length > 1 ? routerArr[routerArr.length - 2].data.router : '',
      name: routerArr[routerArr.length - 1].data.pagetitle,
      address: this.data.id,
      String4: item.cta_button_name,

    }
    let track = UserAccess(UserAccessoptions)

    // 自定义埋点
    let customAccessoptions = {
      customType: 'TileCTA_' + this.data.tilesDetail.tile_info.id + '_' + item.cta_button_name
      // tileId: this.data.tilesDetail.tile_info.id,
      // ctabtn: this.data.tilesDetail.tile_info.cta[0].cta_button_name
    }

    let tracks = addUserStat(customAccessoptions)

  }
})